//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Input;
using OpenLS.UI.Internals;

namespace OpenLS.UI
{
    public class OfficeApplicationCommands
    {
        private static readonly RoutedUICommand[] _internalCommands = new RoutedUICommand[(int) CommandId.Last];

        public static RoutedUICommand Exit
        {
            get { return ensureCommand(CommandId.Exit); }
        }

        public static RoutedUICommand RepeatLastCommand
        {
            get { return ensureCommand(CommandId.RepeadLastCommand); }
        }

        public static RoutedUICommand CheckSpelling
        {
            get { return ensureCommand(CommandId.CheckSpelling); }
        }

        public static RoutedUICommand Options
        {
            get { return ensureCommand(CommandId.Options); }
        }

        public static RoutedUICommand SetForeground
        {
            get { return ensureCommand(CommandId.SetForeground); }
        }

        public static RoutedUICommand SetBackground
        {
            get { return ensureCommand(CommandId.SetBackground); }
        }

        private static string getUIText(CommandId idCommand)
        {
            switch (idCommand)
            {
                case CommandId.Exit:
                    return UIStringTable.Exit;
                case CommandId.CheckSpelling:
                    return UIStringTable.CheckSpelling;
                case CommandId.Options:
                    return UIStringTable.Options;
                case CommandId.SetForeground:
                    return UIStringTable.SetForeground;
                case CommandId.SetBackground:
                    return UIStringTable.SetBackground;
                    case CommandId.RepeadLastCommand:
                    return "Repeat";
                default:
                    throw new NotSupportedException();
            }
        }

        private static RoutedUICommand ensureCommand(CommandId idCommand)
        {
            lock (_internalCommands.SyncRoot)
            {
                if (_internalCommands[(int) idCommand] == null)
                {
                    var newCommand = new RoutedUICommand(getUIText(idCommand), idCommand.ToString(),
                                                         typeof (OfficeApplicationCommands));
                    _internalCommands[(int) idCommand] = newCommand;
                }
            }
            return _internalCommands[(int) idCommand];
        }

        #region Nested type: CommandId

        private enum CommandId
        {
            Exit,
            Options,
            SetForeground,
            SetBackground,
            CheckSpelling,
            RepeadLastCommand,
            Last
        }

        #endregion
    }
}